package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Orders;
import com.example.demo.service.OrdersService;
import com.example.demo.mapper.OrdersMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author GJC
* @description 针对表【orders】的数据库操作Service实现
* @createDate 2025-01-12 23:14:37
*/
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders>
    implements OrdersService{
    //生成订单接口，接收购物车中的图书信息并生成订单
    public int createOrder(Orders orders){
        return this.baseMapper.insert(orders);
    }
    //获取所有订单接口，返回用户所有订单列表
    public List<Orders> getList(int user_id){
        QueryWrapper<Orders> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("user_id",user_id);
        return this.baseMapper.selectList(queryWrapper);
    }
    //获取单个订单详情接口，根据订单ID返回订单详细信息
    public Orders getOrder(int id){
        return this.baseMapper.selectById(id);
    }
    //更新订单状态接口，根据订单ID更新订单状态
    public int updateOrderStatus(int id, String status){
        Orders orders = new Orders();
        orders.setId(id);
        orders.setStatues(status);
        return this.baseMapper.updateById(orders);
    }
}




